/*
author: Jackong
*/
#pragma once

#include <mysql.h>
#pragma comment(lib, "libmysql.lib")

#include "singleton.h"

using namespace fly::jld::jack::dp;

#include <boost\thread\mutex.hpp>

class db_manager
	:protected singleton<db_manager>
{
	friend class singleton<db_manager>; 
private:
	boost::mutex qry_mutex_;
	MYSQL mysql_;
	db_manager();
	~db_manager(){}
	bool set_autocommit(bool at);
public:
	bool connect();
	bool prepare_manual_commit();
	bool commit();
	bool query(const char* cmd, MYSQL_RES* res = NULL);
	bool query_non_lock(const char* cmd, MYSQL_RES* res = NULL);
	void escape(string& val);
	
};

#define DBM singleton<db_manager>::instance()